package com.jinzhi.jinzhidata.repository;

import com.jinzhi.jinzhidata.dataobject.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * @description
 * @date 2019-12-28 11:55
 **/
@Repository
public interface UserRepository extends JpaRepository<User, String> {

    @Modifying
    @Query("update User set userBalance=userBalance + :changedBalance where userId = :userId and (userBalance + :changedBalance)>=0")
    Integer updateUserBalance(String userId, BigDecimal changedBalance);
}
